// MainDlg.h : interface of the CMainDlg class
//
/////////////////////////////////////////////////////////////////////////////

#pragma once
#include <atlstr.h>
#include <map>

class CMainDlg : public CDialogImpl<CMainDlg>, public CUpdateUI<CMainDlg>,
		public CMessageFilter, public CIdleHandler
{
protected:
	typedef enum
	{
		enFile = 0x00,
		enFolder
	}ENUM_FileType;

public:
	enum { IDD = IDD_MAINDLG };

	virtual BOOL PreTranslateMessage(MSG* pMsg);
	virtual BOOL OnIdle();

	BEGIN_UPDATE_UI_MAP(CMainDlg)
	END_UPDATE_UI_MAP()

	BEGIN_MSG_MAP(CMainDlg)
		MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
		MESSAGE_HANDLER(WM_DESTROY, OnDestroy)
		COMMAND_ID_HANDLER(ID_APP_ABOUT, OnAppAbout)
		COMMAND_ID_HANDLER(IDOK, OnOK)
		COMMAND_ID_HANDLER(IDCANCEL, OnCancel)
		COMMAND_HANDLER(ID_SELECT_DIR, BN_CLICKED, OnBnClickedSelectDir)
		COMMAND_HANDLER(ID_BTN_REPLACE_READY, BN_CLICKED, OnBnClickedBtnReplaceReady)
		COMMAND_HANDLER(ID_BTN_REPLACE_DO, BN_CLICKED, OnBnClickedBtnReplaceDo)
		COMMAND_HANDLER(IDC_EDIT_FILE_DIR, EN_CHANGE, OnEnChangeEditFileDir)
		COMMAND_HANDLER(IDC_EDIT_FILE_DIR, EN_SETFOCUS, OnEditSetFocus)
		COMMAND_HANDLER(IDC_EDIT_FILE_DIR, EN_KILLFOCUS, OnEditKillFocus)
		COMMAND_HANDLER(IDC_EDIT_NAME_2_REPLACE, EN_SETFOCUS, OnEditSetFocus)
		COMMAND_HANDLER(IDC_EDIT_NAME_2_REPLACE, EN_KILLFOCUS, OnEditKillFocus)
		COMMAND_HANDLER(IDC_EDIT_FILE_REPLACE_WITH, EN_SETFOCUS, OnEditSetFocus)
		COMMAND_HANDLER(IDC_EDIT_FILE_REPLACE_WITH, EN_KILLFOCUS, OnEditKillFocus)
		
	END_MSG_MAP()

// Handler prototypes (uncomment arguments if needed):
//	LRESULT MessageHandler(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
//	LRESULT CommandHandler(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
//	LRESULT NotifyHandler(int /*idCtrl*/, LPNMHDR /*pnmh*/, BOOL& /*bHandled*/)

	LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);
	LRESULT OnDestroy(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);
	LRESULT OnAppAbout(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
	LRESULT OnOK(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
	LRESULT OnCancel(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/);

	void CloseDialog(int nVal);
	LRESULT OnBnClickedSelectDir(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);

private:
	CString m_strSourceDir;
	CEdit m_editFileSourceDir;
	CString m_strName2Replace;
	CEdit m_editName2Replace;
	CString m_strNameReplaceWith;
	CEdit m_editNameReplaceWith;
	BOOL m_bIsRecursive;
	BOOL m_bIncludeDirName;

	CListViewCtrl m_lstMonitor;
	std::map<CString, CString> m_mapFileMap;
	std::map<CString, CString> m_mapFolderMap;
public:
	LRESULT OnBnClickedBtnReplaceReady(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
	LRESULT OnBnClickedBtnReplaceDo(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
	LRESULT OnEnChangeEditFileDir(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);

protected:
	LRESULT OnEditSetFocus(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
	LRESULT OnEditKillFocus(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);


	
protected:
	void ClearData();
	void FillNameInputInfo();
	BOOL SecureCheck();
	void RecursiveFindFile(const CString& strPath);
	BOOL CheckAddPath(const CString& strFolder, const CString& strOldFileName, ENUM_FileType Type);
	void AddNewListItem( const CString& strFolder, const CString& strileName, ENUM_FileType Type);
};
